/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Form;

import data.Cell;
import data.Row;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author GREENWIND
 */
public final class ShowResult extends JPanel{
    ArrayList<Row> listresult;
    JTable table;
    DefaultTableModel tableModel;
    JScrollPane jsp;
    JTabbedPane pane;
    public ShowResult(JTabbedPane jtp,ArrayList<Row> list)
    {
        super(new FlowLayout(FlowLayout.LEFT, 0, 0));
        
        if (jtp == null) {
            throw new NullPointerException("TabbedPane is null");
        }
        this.pane = jtp;
        this.listresult = list;
        setOpaque(false);
        InitTable();
        add(jsp);
        setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));  
    }
    public void InitTable()
    {
        int nRows = listresult.size();
        int nCols = listresult.get(0).getnCell();
        Object[] ob = new Object[nCols];
        for (int j = 0; j < nCols; j++) {
            ob[j] = listresult.get(0).getListCell().get(j).getName();
        }
        tableModel = new DefaultTableModel(ob, nRows);
        table = new JTable(tableModel);
        jsp = new JScrollPane(table);        
        for(int i = 0; i < nRows; i++)
        {
                    ArrayList<Cell> cells = listresult.get(i).getListCell();
            for(int j = 0; j < nCols; j ++)
            {
                table.getModel().setValueAt(cells.get(j).getData(), i, j);
            }
        }
    }
}
